<?php
/**
 * Created by PhpStorm.
 * User: Bzing
 * Date: 2017/7/25
 * Time: 12:34
 */
namespace app\crontab\controller;
use app\models\Models;
use think\Controller;
use think\Db;

class Day extends Controller {
    /**
     * 定时失效扫码用户
     * 每天7点执行计划任务
     * @return string
     */
    public function autoInvalidScan(){
        $sql = 'update it_scan set status ='.Models::SCAN_NOT;
        $bool = Db::execute($sql);
        if(false === $bool){
            return 'error';
        } else{
            return 'success';
        }
    }

    /**
     * 定时结束活动
     * 每天7点执行计划任务
     * @return string
     */
    public function autoFinishEvent(){
        $sql = 'update it_activity set status = '.Models::STATUS_OVER.' where status = '.Models::STATUS_ON;
        $bool = Db::execute($sql);
        if(false === $bool){
            return 'error';
        } else {
            return 'success';
        }
    }

    /**
     * 定时取消酒桌预定
     * 每天7点执行计划任务
     * @return string
     */
    public function autoCancelReserve(){
        $sql = 'update it_table set is_reserve = '.Models::TABLE_NOT;
        $bool = Db::execute($sql);
        if(false === $bool){
            return 'error';
        } else {
            return 'success';
        }
    }

    /**
     * 定时失效代金券
     * 每天0点执行计划任务
     * @return string
     */
    public function autoInvalidVoucher(){
        $time = time();
        $sql = 'update it_voucher set status = '.Models::VOUCHER_OVER.' where end_time < '.$time;
        $bool = Db::execute($sql);
        if(false === $bool){
            return 'error';
        } else {
            return 'success';
        }
    }
}